#pragma once
#ifndef xRenderTarget_h__
#define xRenderTarget_h__

#include "../../../dxhead/dxegheader.h"
#include "../../../xlib/xlib.h"
#include "./xPict.h"
namespace Sky
{
	class xCanvas : public xDeviceRes<xDevice*>
	{
	public:
		static TVoid StaticInit(TUint D3DCLEAR_ = D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET,D3DCOLOR clearColor = 0,TFloat Zdepth = 1.0f,TUint Stencil = 0)
		{
			ms_Flag = D3DCLEAR_;
			ms_Color = clearColor;
			ms_Zdepth = Zdepth;
			ms_Stencil = Stencil;
			ms_bRected = vFalse;
		}
	public:
		TResult Attach(xPict* pict,TInt level = 0);
		TVoid	Detach();
	public:
		xCanvas();
		~xCanvas();
	private:
		TVoid Initialise();
		TVoid Finalise();
	protected:
		virtual TResult onCreate(xDxApp* app);
		virtual TResult onDelete(xDxApp* app);
		//xRes
		virtual TResult onCreate(xDevice* device);
		virtual TResult onReset(xDevice* device) ;
		virtual TResult onLost(xDevice* device);
		virtual TResult onDelete(xDevice* device);
	public:
		xCanvas& setRect(D3DRECT* rect);
		xCanvas& setClearFlag(TUint D3DCLEAR_ = D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET){m_Flag = D3DCLEAR_;return *this;}
		xCanvas& setClearColor(D3DCOLOR clearColor = 0){m_Color = clearColor; return *this;}
		xCanvas& setClearZdepth(TFloat z){m_Zdepth = z; return *this;}
		xCanvas& setClearStencil(TUint stencil){m_Stencil = stencil;return *this;}
		xCanvas& setViewPort(D3DVIEWPORT9 * pViewport);
		xCanvas& getViewPort(D3DVIEWPORT9 * pViewport);
		xPict* getPict(){return m_curSurf;}
	private:
		static TUint ms_Flag;
		static D3DCOLOR ms_Color;
		static TFloat ms_Zdepth;
		static TUint ms_Stencil;
		static TBool ms_bRected;
	private:
		IDirect3DSurface9* m_pPrev;
		xPict* m_curSurf;
		TInt m_levelPrev;
		D3DRECT m_Rect;
		TUint m_Flag;
		D3DCOLOR m_Color;
		TFloat m_Zdepth;
		TUint  m_Stencil;
		TBool m_bRected;
	};

}
#endif // xRenderTarget_h__